package com.netjava.service.impl;

import java.util.List;

import com.netjava.dao.IUserDAO;
import com.netjava.pojo.User;
import com.netjava.service.IUserService;
/**
 * 用户业务的实施类。
 * @author nana
 *
 */
public class UserService implements IUserService {
	private IUserDAO userDao;
	public void addUser(User user){
		userDao.save(user);
	}
	public void delete(User user){
		userDao.delete(user);
	}
	public User getUserById(java.lang.Integer id){
		return userDao.findById(id);
	}
	@SuppressWarnings("unchecked")
	public User getByUserName(String userName){
		List<User> userList=userDao.findByUserName(userName);
		if(null!=userList){
			if(userList.size()>0){
				return (User)userList.get(0);
			}
			return null;
		}
		else{
			return null;
		}
	}
	public IUserDAO getUserDao() {
		return userDao;
	}
	public void setUserDao(IUserDAO userDao) {
		this.userDao = userDao;
	}
	public void attachDirty(User instance) {
		userDao.attachDirty(instance);
		
	}
	@SuppressWarnings("unchecked")
	public List<User> getAllUser() {
		List<User> userList=userDao.findAll();
		return userList;
	}
	public List<User> getNumUsers(Integer page,Integer num){
		List<User> userList=userDao.getNumUsers(page, num);
		return userList;
	}
}
